package br.edu.unifas.es5.bd2.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Calendar;

public class Main3 {

	public static void main(String[] args) {
		try {
			Class.forName("org.postgresql.Driver");
			
			Calendar cal = Calendar.getInstance();
			cal.set(Calendar.YEAR, 1994);
			cal.set(Calendar.MONTH, Calendar.AUGUST);
			cal.set(Calendar.DAY_OF_MONTH, 4);
			
			Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/aluno", "aluno", "aluno");
			conn.setAutoCommit(false);
			PreparedStatement ps = conn.prepareStatement("insert into aluno (nome, matricula, nascimento) values (?,?,?) ");
			ps.setString(1, "aluno 8");
			ps.setInt(2, 8);
			ps.setTimestamp(3, new Timestamp(cal.getTimeInMillis()));
			ps.execute();
			
			conn.commit();
			
			ps.close();
			conn.close();

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
